<template>
  <div class="app-container">
    <div class="search-container">
      <el-form inline>
        <el-form-item label="名称">
          <el-input />
        </el-form-item>
        <el-button type="primary">搜索</el-button>
        <!-- <el-button type="primary" @click="operate('add')">新增</el-button> -->
        <!-- <el-button type="primary">导入</el-button>
        <el-button type="primary">导出</el-button> -->
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="项目名称" width="200px" align="center">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="项目编号" align="center">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="位置" align="center">
        <template slot-scope="scope">
          {{ scope.row.place }}
        </template>
      </el-table-column>
      <el-table-column label="项目负责人" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分配时间" width="180" align="center">
        <template slot-scope="scope">
          {{ scope.row.display_time }}
        </template>
      </el-table-column>
      <el-table-column
        class-name="status-col"
        label="项目状态"
        width="110"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{
            scope.row.status | statusFilterLabel
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.remark }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column align="center" prop="created_at" label="Display_time" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.display_time }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" width="110" align="center" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button
            type="primary"
            size="mini"
            :disabled="scope.row.status == 0"
            >发布</el-button
          >
          <el-button
            type="warning"
            size="mini"
            :disabled="scope.row.status == 1"
            >停用</el-button
          >
          <el-button type="success" size="mini">修改</el-button>
          <el-button type="danger" size="mini">删除</el-button> -->
          <el-button type="success" size="mini" @click="detail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" :title="title" width="800px">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="巡检计划名称">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="巡查人">
          <el-select v-model="form.person" placeholder="请选择巡查人">
            <el-option
              v-for="(item, index) in personList"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="类目">
          <el-select v-model="form.region" placeholder="请选择类目">
            <el-option
              v-for="(item, index) in typeList"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查频次">
          <el-select v-model="form.num" placeholder="请选择巡查人">
            <el-option
              v-for="(item, index) in numList"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查时间">
          <el-col :span="11">
            <el-date-picker
              v-model="form.date1"
              type="date"
              placeholder="选择日期"
              style="width: 100%"
            />
          </el-col>
          <el-col :span="2" class="line">-</el-col>
          <el-col :span="11">
            <el-time-picker
              v-model="form.date2"
              type="fixed-time"
              placeholder="选择时间"
              style="width: 100%"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="是否发布">
          <el-switch v-model="form.delivery" />
        </el-form-item>

        <!-- <el-form-item label="Resources">
          <el-radio-group v-model="form.resource">
            <el-radio label="Sponsor" />
            <el-radio label="Venue" />
          </el-radio-group>
        </el-form-item>
        <el-form-item label="Activity form">
          <el-input v-model="form.desc" type="textarea" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button @click="onCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from "@/api/table";

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: "success",
        1: "gray",
        2: "danger",
        3: "warning",
      };
      return statusMap[status];
    },
    statusFilterLabel(status) {
      const statusMap = {
        0: "进行中",
        1: "已完成",
        2: "待验收",
        3: "未开始",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      list: null,
      listLoading: true,
      data: [
        {
          name: "张三",
          type: "基础类",
          author: "李响",
          display_time: "2023-12-24 16:10:10",
          id: "2104623",
          pageviews: 1165,
          status: 1,
          place: "拱墅区",
          remark: "11111",
        },
        {
          name: "李四",
          type: "完善类",
          author: "李响",
          display_time: "2023-12-24 16:10:10",
          id: "2104622",
          pageviews: 1165,
          status: 0,
          place: "拱墅区",
          remark: "11111",
        },
        {
          name: "王五",
          type: "提升类",
          author: "李响",
          display_time: "2023-12-24 16:10:10",
          id: "2104628",
          pageviews: 1165,
          status: 2,
          place: "拱墅区",
          remark: "11111",
        },
      ],
      dialogVisible: false,
      title: "新增巡检计划",
      personList: [{ label: "张三", value: "0" }],
      numList: [
        { label: "每年", value: "0" },
        { label: "每月", value: "1" },
        { label: "每日", value: "2" },
      ],
      typeList: [
        { label: "消防安全", value: "0" },
        { label: "食堂安全", value: "1" },
        { label: "护工查房", value: "2" },
      ],
      form: {},
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      this.list = this.data;
      this.listLoading = false;
      // getList().then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    },
    operate(type) {
      if (type === "add") {
        this.dialogVisible = true;
      }
    },
    detail(row) {
      if (row.status == 0) {
        this.$router.push({ name: "ConstructionDetailing" });
      } else {
        this.$router.push({ name: "ConstructionDetail" });
      }
    },
    onSubmit() {
      this.$message("submit!");
    },
    onCancel() {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped>
.line {
  text-align: center;
}
</style>
